<template>
	<view v-if="params.url">
		<web-view :webview-styles="webviewStyles" :src="`${params.url}`" @message="handleMessage"></web-view>
	</view>
</template>

<script>
	import {
		setToken,getToken
	} from '@/utils/auth'
	import {
		mapServerUrl
	} from '@/config.js'
	import { queryGeocoder } from '@/api/mapGis/mapGis'
	export default {
		data() {
			return {
				params: {},
				webviewStyles: {
					progress: {
						color: "#FF3333"
					}
				},
				token: null
			}
		},
		props: {
			src: {
				type: [String],
				default: null
			}
		},
		onLoad(event) {
			console.log(event)
			this.params = event
			console.log(JSON.stringify(event))
			// 正式版 地址 http://10.8.88.26:6061/#/  http://localhost:3000/#/ 
			// let url = 'http://10.8.88.26:6062/#/'
			let url = mapServerUrl
			// if (!event.aurl) {
			// 	event.aurl = "pages/waterSupply/DailyManagement/map/map";
			// 	//this.params.url = url + event.aurl
			// }
			if (!event.token) {
				event.token = getToken()
				// 正式版 地址 http://10.8.88.26:6061/#/
				//this.params.url = url + event.aurl + '?token=' + event.token
			}
			this.params.url = url + decodeURI(event.url) + '?token=' + event.token + '&location='+event.location
			console.log(this.params.url);
			
		},
		methods: {
			handleMessage(evt) {
				const eventChannel = this.getOpenerEventChannel();
				console.log(JSON.stringify(evt));
				console.log('接收Html发送过来的消息：' + JSON.stringify(evt.detail.data[0]));
				let coordinate = evt.detail.data[0];
				coordinate.ver = "1";
				console.log(coordinate.lat)
				let params = {
					"postStr":JSON.stringify(coordinate),
					"type":"geocode"
				}
				queryGeocoder(params).then(res => {
					console.log(res)
					if(res.result){
						coordinate.address = res.result.formatted_address
					}
					eventChannel.emit('acceptDataFromOpenedPage', {coordinate: coordinate});
				})
				
			},
		}
	}
</script>